package com.feihong.txgw.tx_precenter;

import com.feihong.txgw.inter.contract.pay.IPayContract;
import com.feihong.txgw.json.pay.JiFenParser;
import com.feihong.txgw.tx_model.PayMainModel;
import com.feihong.txgw.utils.manage.RetrofitManager;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;

/**
 * @Author wangziheng
 * @ProjectName txgw_app
 * @ClassName PayMainPrecenter
 * @package com.feihong.txgw.tx_precenter
 * @data 2018/5/4 18:46
 * @Describe
 * @Change
 */
public class PayMainPrecenter extends IPayContract.AbPayMainPrecenter {

    public static PayMainPrecenter create(){
        return new PayMainPrecenter();
    }
    @Override
    public void loadOrderJiFenInfo(String orderSn, String orderType) {
        mIModel.getOrderJiFenInfo(orderSn,orderType).subscribe(new Observer<JiFenParser>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(JiFenParser o) {
                mIView.loadOrderJiFenResult(o);
            }

            @Override
            public void onError(Throwable e) {
                mIView.loadOrderJiFenError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public void createWechatPayOrder(String orderID, String price, String orderName, String handle_notify, String use_point, String payType) {
        mIModel.createWechatPayOrder(orderID, price, handle_notify, use_point, payType,orderName)
        .subscribe(new Observer<String>() {
            @Override
            public void onSubscribe(Disposable d) {
                mRxManager.register(d);
            }

            @Override
            public void onNext(String s) {
                mIView.createWechatPayOrderResult(s);
            }

            @Override
            public void onError(Throwable e) {
                mIView.createWechatPayOrderError();
            }

            @Override
            public void onComplete() {

            }
        });
    }

    @Override
    public IPayContract.IPayMainModel getModel() {
        return PayMainModel.create();
    }

    @Override
    public void onStart() {

    }
}
